<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <!-- 用于对标签属性进行限制 -->
    <script src="../js/prop-types.js"></script>
</head>

<body>
    <div id="test"></div>
    <div id="test2"></div>
    <script type="text/babel">
        class Person extends React.Component {
            state={}

            // 制定传入参数props的限制规则
            static propTypes={
                name:PropTypes.string.isRequired,
                age:PropTypes.number,
                sex:PropTypes.string,
            }
            static defaultProps = {
                age:18
            }

            render() {
                let { name, sex, age } = this.props
                age += 1;
                return (
                    <ul>
                        <li>姓名:{name}</li>
                        <li>性别:{sex}</li>
                        <li>年龄:{age}</li>
                    </ul>
                )
            }

        }

       

        ReactDOM.render(<Person name='tom' sex={9} />, document.getElementById('test'))
        
        // 模拟后台返回的数据
        // const p1 = {
        //     name: "kiki",
        //     sex: '女',
        //     age: 20
        // }
        // ReactDOM.render(<Person {...p1} />, document.getElementById('test2'))


    </script>
</body>

</html>